/* -----------------------------------------------------------------------
 * Paul Cohen
 * CS 362, Summer 2014
 * Assignment 3
 *
 * unittest3.c - testing Dominion's buyCard() function
 * 
 * -----------------------------------------------------------------------
 */

#include "unittest3.h"
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>


int unit_test3()
{
    int seed = 1000;
    int numPlayers = 2;
    int successes = 0;
    
    struct gameState g;
    int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
    
    printf("\nUnit Test 3: testing buyCard()\n------------\n");        
    initializeGame(numPlayers, k, seed, &g);
    
    // test various cases in buyCard() with the estate card
    g.numBuys = 0;
    if (buyCard(1, &g) == -1)
        successes++;
    else 
        printf("Test failed - can't buy when number of buys is 0.\n");
    
    g.numBuys = 1;
    g.supplyCount[1] = 0;
    if (buyCard(1, &g) == -1)
        successes++;
    else 
        printf("Test failed - card supply count at 0.\n");
    
    g.supplyCount[1] = 1;
    g.coins = 1;
    if (buyCard(1, &g) == -1)
        successes++;
    else 
        printf("Test failed - not enough coins.\n");
    
    g.coins = 3;
    buyCard(1, &g);
    if(g.phase == 1)
        successes++;
    else
        printf("Test failed - turn phase not set correctly.\n");
    
    if(g.coins == 1)
        successes++;
    else
        printf("Test failed - coins not removed correctly.\n");
    
    if(g.numBuys == 0)
        successes++;
    else
        printf("Test failed - number of buys not set correctly.\n");

    printf("buyCard() tests completed!\n");
    printf("%d out of 6 tests successful.\n", successes);

    return 0;
}
